package com.gb.demand.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gb.demand.common.dto.OrderBO;
import com.gb.demand.common.dto.OrderBOS;
import com.gb.demand.common.dto.OrderFormDTO;
import com.gb.demand.common.entity.Address;
import com.gb.demand.common.entity.Goods;
import com.gb.demand.common.entity.Goodscart;
import com.gb.demand.common.entity.Orderform;
import com.gb.demand.common.mapper.OrderformMapper;
import com.gb.demand.service.IOrderformService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户业务层模块<p>
 *
 * @author wengjiangle
 * @since 2020/7/13
 */
@Slf4j
@Service
public class OrderformServiceImpl extends ServiceImpl<OrderformMapper, Orderform> implements IOrderformService {

    @Resource
    private OrderformMapper orderformMapper;

    @Override
    public List<OrderFormDTO> getListbyIds(List<Long> orderformIds) {
        return orderformMapper.getListbyIds(orderformIds);
    }

    @Override
    public List<OrderBO> getOrdersAll() {
        List<OrderBOS> list = orderformMapper.getOrdersAll();
        list.forEach(x -> {
            List<Goodscart> goodscarts = new Goodscart().selectList(new LambdaQueryWrapper<Goodscart>().eq(Goodscart::getOfId, x.getId()));
            String s = "";
            for (Goodscart goodscart : goodscarts) {
                Goods goods = new Goods().selectById(goodscart.getGoodsId());
                s = s + goods.getGoodsName();
            }
            x.setOrderDetail(s);
        });
        List<OrderBO> convert = Convert.convert(new TypeReference<List<OrderBO>>() {
        }, list);
        return convert;
    }
}
